using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace PrivateEngine
{
	
	class MainClass
	{
		     
		
		public static void Main (string[] args)
		{
	 
			DateTime startTime = DateTime.Now;
			string petit_path = "petit.exe";
			string petit_flags = " -Fc -4 -g";

			
			string tmp_folder = "out/";
			string loop_file = args[0];
		
   			ProcessStartInfo pInfo = new ProcessStartInfo();
			pInfo.UseShellExecute = false;
		    pInfo.FileName = petit_path;
			pInfo.Arguments = " " /* + loops_folder */ + loop_file + petit_flags;

			
			pInfo.RedirectStandardOutput = true;
			Process p = Process.Start(pInfo);
			string output = p.StandardOutput.ReadToEnd();
						p.WaitForExit();
			

			StreamWriter sw = new StreamWriter(tmp_folder + Path.GetFileName(loop_file) + ".deps");
			sw.WriteLine(output);	
			sw.Close();
			
			
			//Environment.Exit(1);
			
			// --------------------
		  
			
			ParseTree pt = new ParseTree(/* + loops_folder */ loop_file);
			pt.ReadParseTree();
			pt.Parallelize(tmp_folder + Path.GetFileName(loop_file) + ".deps");
			pt.GenerateCode(tmp_folder + "out_" + Path.GetFileName(loop_file));
			
			Console.WriteLine();
			Console.WriteLine("See the file: " + tmp_folder + "out_" + Path.GetFileName(loop_file));
			DateTime stopTime = DateTime.Now;
			TimeSpan duration = stopTime - startTime;
			Console.WriteLine(duration);
			
			 
		}
		
	}
}

